
Public Class Privilege

    Protected _privilege_id As Integer
    Protected _privilege_name_tha As String
    Protected _privilege_name_eng As String
    Protected _description As String
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property privilege_id() As Integer
        Get
            Return _privilege_id
        End Get
        Set(ByVal value As Integer)
            _privilege_id = value
        End Set
    End Property

    Public Property privilege_name_tha() As String
        Get
            Return _privilege_name_tha
        End Get
        Set(ByVal value As String)
            _privilege_name_tha = value
        End Set
    End Property

    Public Property privilege_name_eng() As String
        Get
            Return _privilege_name_eng
        End Get
        Set(ByVal value As String)
            _privilege_name_eng = value
        End Set
    End Property

    Public Property description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

    Public Function getPrivilege() As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Privilege"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Privilege")

        Return objDs
    End Function

    Protected Function getsPrivilege() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Privilege"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Privilege")

        For Each objDr As System.Data.DataRow In objDs.Tables("Privilege").Rows
            Dim obj As Privilege = New Privilege()
            obj.privilege_id = objDr.Item("privilege_id").ToString()
            obj.privilege_name_tha = objDr.Item("privilege_name_tha").ToString()
            obj.privilege_name_eng = objDr.Item("privilege_name_eng").ToString()
            obj.description = objDr.Item("description").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Sub LoadPrivilege()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsPrivilege()
    End Sub

    Public Overloads Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _privilege_id = _Data(_DataCurrent).privilege_id
            _privilege_name_tha = _Data(_DataCurrent).privilege_name_tha
            _privilege_name_eng = _Data(_DataCurrent).privilege_name_eng
            _description = _Data(_DataCurrent).description

            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Function deletePrivilege(ByVal inPrivilegeID As String) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_Privilege"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeID", _
                Utilities.SendToDatabase(inPrivilegeID))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function insertPrivilege(ByVal inPrivilege As Privilege) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_Privilege"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeID", _
                Utilities.SendToDatabase(inPrivilege.privilege_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeNameTha", _
                Utilities.SendToDatabase(inPrivilege.privilege_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeNameEng", _
                Utilities.SendToDatabase(inPrivilege.privilege_name_eng))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inPrivilegeDescription", _
                Utilities.SendToDatabase(inPrivilege.description))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function selectMaxPrivilegeID() As Integer
        Try
            Dim outResult As Integer = 0
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_SELECT_MAXPrivilegeID"

            objConn.Open()
            If IsDBNull(objCmd.ExecuteScalar()) Then
                outResult = 0
            Else
                outResult = CInt(objCmd.ExecuteScalar())
            End If
            objConn.Close()

            Return outResult
        Catch ex As Exception
            Throw ex
        End Try
    End Function

End Class
